package com.runner.services;

import com.badlogic.gdx.Preferences;
import com.runner.utility.Constants;
import com.runner.utility.Locator;

public class AccomplishmentsOutbox implements Constants {
	private Achievements achvs;
	int distanceRinger1 = 0;
	int distanceRinger2 = 0;
	int distanceApril1 = 0;
	int distanceApril2 = 0;
	int distanceGeo1 = 0;
	int distanceGeo2 = 0;

	public AccomplishmentsOutbox(Achievements achvs) {
		this.achvs = achvs;
	}

	boolean isFull() {
		return false;
	}

	public void saveLocal(Preferences prefs) {
		prefs.putInteger("distanceRinger1", distanceRinger1);
		prefs.putInteger("distanceRinger2", distanceRinger2);
		prefs.putInteger("distanceApril1", distanceApril1);
		prefs.putInteger("distanceApril2", distanceApril2);
		prefs.putInteger("distanceGeo1", distanceGeo1);
		prefs.putInteger("distanceGeo2", distanceGeo2);

		// achievements
		prefs.putBoolean("ringer1", achvs.isRinger1());
		prefs.putBoolean("ringer2", achvs.isRinger2());
		prefs.putBoolean("april1", achvs.isApril1());
		prefs.putBoolean("april2", achvs.isApril2());
		prefs.putBoolean("geo1", achvs.isGeo1());
		prefs.putBoolean("geo2", achvs.isGeo2());
		prefs.putBoolean("ringerShield", achvs.isRingerShield());
		prefs.putBoolean("aprilShield", achvs.isAprilShield());
		prefs.putBoolean("geoShield", achvs.isGeoShield());
		prefs.putBoolean("hoarder", achvs.isHoarder());
		prefs.putBoolean("unlock", achvs.isUnlock());
	}

	public void loadLocal(Preferences prefs) {
		distanceRinger1 = prefs.getInteger("distanceRinger1", 0);
		distanceRinger2 = prefs.getInteger("distanceRinger2", 0);
		distanceApril1 = prefs.getInteger("distanceApril1", 0);
		distanceApril2 = prefs.getInteger("distanceApril2", 0);
		distanceGeo1 = prefs.getInteger("distanceGeo1", 0);
		distanceGeo2 = prefs.getInteger("distanceGeo2", 0);

		// achievements
		achvs.setRinger1(prefs.getBoolean("ringer1", false));
		achvs.setRinger2(prefs.getBoolean("ringer2", false));
		achvs.setApril1(prefs.getBoolean("april1", false));
		achvs.setApril2(prefs.getBoolean("april2", false));
		achvs.setGeo1(prefs.getBoolean("geo1", false));
		achvs.setGeo2(prefs.getBoolean("geo2", false));
		achvs.setRingerShield(prefs.getBoolean("ringerShield", false));
		achvs.setAprilShield(prefs.getBoolean("aprilShield", false));
		achvs.setGeoShield(prefs.getBoolean("geoShield", false));
		achvs.setHoarder(prefs.getBoolean("hoarder", false));
		achvs.setUnlock(prefs.getBoolean("unlock", false));
	}

	public void pushAccomplishments() {
		if (achvs.isHoarder()) {
			achvs.unlock(ACHV_HOARDER);
		}
		if (achvs.isUnlock()) {
			achvs.unlock(ACHV_UNLOCK);
		}
		if (achvs.isRinger1()) {
			achvs.unlock(ACHV_RINGER1_TRACK);
		}
		if (achvs.isRinger2()) {
			achvs.unlock(ACHV_RINGER2_TRACK);
		}
		if (achvs.isApril1()) {
			achvs.unlock(ACHV_APRIL1_TRACK);
		}
		if (achvs.isApril2()) {
			achvs.unlock(ACHV_APRIL2_TRACK);
		}
		if (achvs.isGeo1()) {
			achvs.unlock(ACHV_GEO1_TRACK);
		}
		if (achvs.isGeo2()) {
			achvs.unlock(ACHV_GEO2_TRACK);
		}
		if (achvs.isRingerShield()) {
			achvs.unlock(ACHV_RINGER2_TRACK_SHIELD);
		}
		if (achvs.isAprilShield()) {
			achvs.unlock(ACHV_APRIL2_TRACK_SHIELD);
		}
		if (achvs.isGeoShield()) {
			achvs.unlock(ACHV_GEO2_TRACK_SHIELD);
		}

		if (distanceRinger1 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceRinger1, LB_TYPE.RINGER1);
		}
		if (distanceRinger2 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceRinger2, LB_TYPE.RINGER2);
		}
		if (distanceApril1 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceApril1, LB_TYPE.APRIL1);
		}
		if (distanceApril2 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceApril2, LB_TYPE.APRIL2);
		}
		if (distanceGeo1 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceGeo1, LB_TYPE.GEO1);
		}
		if (distanceGeo2 > 0) {
			Locator.getDevice().submitLeaderboardScore(distanceGeo2, LB_TYPE.GEO2);
		}
	}

	public Achievements getAchvs() {
		return achvs;
	}

	public void setAchvs(Achievements achvs) {
		this.achvs = achvs;
	}

	public int getDistanceRinger1() {
		return distanceRinger1;
	}

	public void setDistanceRinger1(int distanceRinger1) {
		this.distanceRinger1 = distanceRinger1;
	}

	public int getDistanceRinger2() {
		return distanceRinger2;
	}

	public void setDistanceRinger2(int distanceRinger2) {
		this.distanceRinger2 = distanceRinger2;
	}

	public int getDistanceApril1() {
		return distanceApril1;
	}

	public void setDistanceApril1(int distanceApril1) {
		this.distanceApril1 = distanceApril1;
	}

	public int getDistanceApril2() {
		return distanceApril2;
	}

	public void setDistanceApril2(int distanceApril2) {
		this.distanceApril2 = distanceApril2;
	}

	public int getDistanceGeo1() {
		return distanceGeo1;
	}

	public void setDistanceGeo1(int distanceGeo1) {
		this.distanceGeo1 = distanceGeo1;
	}

	public int getDistanceGeo2() {
		return distanceGeo2;
	}

	public void setDistanceGeo2(int distanceGeo2) {
		this.distanceGeo2 = distanceGeo2;
	}

}